package com.wenhao.JUC;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Wenhao Tong
 * @create 2021-08-06 0:04
 */
public class LockDemo {
    public static void main(String[] args) {
        Lock lock = new ReentrantLock();
        //Lock是代码实现的接口，而synchronized是JVM底层实现的
        Thread thread = new Thread(() -> {
            lock.lock();
            try {
                System.out.println("加锁代码块");
                //加锁代码块
            } finally {
                //必须手动释放
                lock.unlock();
            }
        });
        thread.start();
    }
}
